package hb.watcher.monitor;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import android.os.Environment;


public class Config {

  private Properties configuration;

  private String configurationFile;

  public Config() {
      configuration = new Properties();
     
      File FileDir = getDir();
      FileDir.mkdirs();
      
      configurationFile = getDir().getPath() + File.separator + "config.ini";
     
      File f = new File(configurationFile);
      try {
		f.createNewFile();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	}
  

  private File getDir() {
		File sdDir = Environment
			.getExternalStorageDirectory();
		return new File(sdDir, "WmTMonitor");
	}
  
  public boolean load() {
	  
      boolean retval = false;

      try {
    	  
          configuration.load(new FileInputStream(this.configurationFile));
          retval = true;
      } catch (IOException e) {
          System.out.println("Configuration error: " + e.getMessage());
      }

      return retval;
  }

  public boolean store() {
      boolean retval = false;

      try {
          configuration.store(new FileOutputStream(this.configurationFile), null);
          retval = true;
      } catch (IOException e) {
          System.out.println("Configuration error: " + e.getMessage());
      }

      return retval;
  }

  public void set(String key, String value) {
      configuration.setProperty(key, value);
  }

  public String get(String key) {
      return configuration.getProperty(key);
  }
}